/*HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
 H       cpu.h
 H       Application name: Program Control Block Header File
 H       Programmers names: Thach Nguyen
 H       Date completed:
 H       Brief Description: This is the header file that defines an ADT for the cpu.
 H
 HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH*/
#ifndef CPU_H_INCLUDED
#define CPU_H_INCLUDED

#include<pthread.h>
#include "queue.h"

#define EXIT_VAR -1
#define INTERRUPT_SERVICE 0
#define TIMER_INTERRUPT 1
#define KEYBOARD_INTERRUPT 2
#define SEM_BLOCK 3
#define IO_INTERRUPT_1 4
#define IO_INTERRUPT_2 5
#define IO_REQUEST 6

#define EXIT_CHAR 'x' //The character that provides an exit for the simulation.

//The cpu struc is mostly a collection of "global vars" that would normally be available to the functions that need it.
typedef struct cpu_str
{
	int pc_reg;
	pthread_mutex_t *run_lock;
	pthread_cond_t *run_cond;
	int run_var;
	pthread_mutex_t *step_lock;

	PQueue *ready_queue;
    PQueue *int_controller;
    pthread_mutex_t *interrupt_lock;
} CPUStr;

typedef CPUStr * CPUPtr;

extern CPUPtr cpu_init(pthread_mutex_t *, pthread_cond_t *, pthread_mutex_t *,
                       PQueue *, PQueue *, pthread_mutex_t *);
extern void cpu_destroy(CPUPtr);
extern void exit_func();
extern void sched_func(int);
extern void contex_switch();
extern void *timer_start(void *);
extern void timer_int_service_routine();
extern void io_int_service_routine(int);
extern void io_int_check_blocked_queue(PQueue *);
extern void ready_queue_pri_check();
extern void *io_1_trap_service_routine(void *);
extern void *io_2_trap_service_routine(void *);

extern int msleep(unsigned long); //More options than sleep()

#endif // CPU_H_INCLUDED
